package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class SpinnerTag extends BodyTagSupport {
	
	private String culture;
	private String disabled;
	private String incremental;
	private String max;
	private String min;
	private String numberFormat;
	private String page;
	private String step;

	@Override
	public int doEndTag() throws JspException {
		
		String spinner = getBodyContent().getString();
		
		JspWriter saida = pageContext.getOut();
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		request.setAttribute("spinner", spinner);
		request.setAttribute("culture",culture);// manda como atributo
		request.setAttribute("disabled",disabled);
		request.setAttribute("incremental",incremental);
		request.setAttribute("max",max);
		request.setAttribute("min",min);
		request.setAttribute("numberFormat",numberFormat);
		request.setAttribute("page",page);
		request.setAttribute("step",step);
		
		ResponseWrapper responseWrapper =  new ResponseWrapper(response);
		
		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/spinner.jsp");
		
		try {
			
			req.include(request, responseWrapper);
			
			String conteudoComponente = responseWrapper.getString();// nessa linha  a interpretação já foi feita
			
			saida.print(conteudoComponente);
			
		} catch (IOException | ServletException e) {
			
			e.printStackTrace();
		}
		
		return super.doEndTag();
	}

	public String getCulture() {
		return culture;
	}

	public void setCulture(String culture) {
		this.culture = culture;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getIncremental() {
		return incremental;
	}

	public void setIncremental(String incremental) {
		this.incremental = incremental;
	}

	public String getMax() {
		return max;
	}

	public void setMax(String max) {
		this.max = max;
	}

	public String getMin() {
		return min;
	}

	public void setMin(String min) {
		this.min = min;
	}

	public String getNumberFormat() {
		return numberFormat;
	}

	public void setNumberFormat(String numberFormat) {
		this.numberFormat = numberFormat;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getStep() {
		return step;
	}

	public void setStep(String step) {
		this.step = step;
	}


	
	
	
	
		
		
}
